<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>罚款列表</title>
    <!-- 引入Bootstrap CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="#">图书馆管理系统 - 罚款列表</a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
                aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item">
                    <a class="nav-link" href="adminDashboardServlet">返回控制面板</a>
                </li>
            </ul>
            <ul class="navbar-nav ms-auto">
                <li class="nav-item">
                    <a class="nav-link" href="logout.jsp">注销登录</a>
                </li>
                <li class="nav-item">
                    <c:if test="${not empty sessionScope.user}">
                        <span class="nav-link">当前登录用户：${sessionScope.user.username}</span>
                    </c:if>
                </li>
            </ul>
        </div>
    </div>
</nav>

<div class="container mt-5">
    <h2>罚款列表</h2>
    <table class="table table-striped">
        <thead>
        <tr>
            <th>罚款ID</th>
            <th>图书名</th>
            <th>用户名</th>
            <th>罚款金额</th>
            <th>罚款截止日期</th>
            <th>是否支付</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="fine" items="${fines}">
            <tr>
                <td>${fine.fineId}</td>
                <td>${fine.getBookname()}</td>
                <td>${fine.getUsername()}</td>
                <td>${fine.amount}</td>
                <td>${fine.dueDate}</td>
                <td>${fine.paid?'是':'否'}</td>
                <td>
                    <c:if test="${sessionScope.user.type==1}">
                        <a href="#" onclick="del('${fine.fineId}')" class="btn btn-danger btn-sm">删除</a>
                    </c:if>
                    <c:if test="${sessionScope.user.id==fine.userId && !fine.paid}">
                        <a href="#" onclick="payFines('${fine.fineId}')" class="btn btn-danger btn-sm">缴纳罚款</a>
                    </c:if>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
</body>
</html>
<script>
    function del(id) {
        // 确认删除
        if (confirm("确定要删除吗？如果这个小可爱还没有交罚款！就收不到钱喽，遭老罪了！")) {
            window.location.href = 'fineServlet?path=del&id=' + id;
        }
    }

    function payFines(id) {
        // 确认删除
        if (confirm("现在实现不了真正的收款！先放你小子一马")) {
            window.location.href = 'fineServlet?path=payFines&id=' + id;
        }
    }
</script>